package com.jmlee.utils;


import com.baidu.aip.ocr.AipOcr;
import org.json.JSONObject;


import java.util.HashMap;

/**
 * @author： 郑锦涛
 * @data： 2021/3/16 22:11
 * @version：1.0
 * @描述： 百度识别图片
 */
public class Sample {
    //设置APPID/AK/SK
    public static final String APP_ID = "23808200";
    public static final String API_KEY = "mGTg3XgrLIDGp3Tb2L9SbkVG";
    public static final String SECRET_KEY = "08wxaeVpGwxr64HYSBeKLkkMp9IXAsMm";

    public static JSONObject sampleIdCard(byte[] image) {
        // 初始化一个AipOcr
        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("detect_direction", "true");
        options.put("detect_risk", "false");

        String idCardSide = "front";

        // 参数为本地图片二进制数组
//        byte[] file = readImageFile(image);
        JSONObject res = client.idcard(image, idCardSide, options);

        return res;
    }
}

